/* main4setCGF.c */
/*Funktionen zum Setzen und Auslesen der Werte in CGF-Objekten Vers. 0.1*/
#include "LoadCGF.h"
#include <conio.h> // _getch()

int main() 
{ int jj1=0, jj2=0, jj3=0;
  CGFobject obj;

//#define MIT_LOADCGF
#ifdef  MIT_LOADCGF
#ifndef  CGF_FILE
  #define CGF_FILE  "..\\..\\_Dat\\cube.cgf"
#endif  //CGF_FILE
  FILE *filecgf=NULL;
  char filnam[LENGTH];
#endif//MIT_LOADCGF

  setTriangleCGF(&obj); 

  /*Ausgabe CGF-Objekt (wie mit printCGF)*/
  printf ("Objekt-Name: %s\n\r", obj.Name);

  printf ("Objektpunkt-Koordinaten:\n\r");
  for (jj1=0; jj1 < obj.nVrtx; jj1++)
  { for (jj2=0; jj2 < NDIM; jj2++)
    { printf("%8.2f", obj.Vrtx[jj1][jj2]);
    } printf("\n\r");
  } printf("\n\n\r");

  /* Ermittlung des Obj.-Pktes zu jedem Flaechen-Pkt aus den Adressen beider: */
  printf ("Flaechen-Punkt-Indizes u. -Koordn. (%d Flaeche/n):\n\r", obj.nFace);
  for (jj1=0; jj1 < obj.nFace; jj1++)
  { printf ("Flaeche[%d] (%d Punkte):\n\r", jj1, obj.Face[jj1].nPnt);
    for (jj2=0; jj2 <obj.Face[jj1].nPnt ; jj2++)
    { 
      jj3 = (obj.Face[jj1].Pnt[jj2] - &obj.Vrtx[0]) 
           /(&obj.Vrtx[1] - &obj.Vrtx[0]);
      printf ("(obj.Face[%d].Pnt[%d] - &obj.Vrtx[0])", jj1, jj2);
      printf ("/(&obj.Vrtx[1] - &obj.Vrtx[0])==%3d \n\r", jj3);
      printf ("Flaeche[%d] Eckpkt[%d] = Obj.-Pkt[%d]: \n\r", 
              jj1, jj2, jj3);
#ifdef   WIRKUNGSGLEICH
          printf("%8.2f, %8.2f, %8.2f\n\r", *(*obj.Face[jj1].Pnt[jj2]+X), 
                 *(*obj.Face[jj1].Pnt[jj2]+Y), *(*obj.Face[jj1].Pnt[jj2]+Z));
#else  //WIRKUNGSGLEICH
          printf("%8.2f, %8.2f, %8.2f\n\r", (*obj.Face[jj1].Pnt[jj2])[X], 
                 (*obj.Face[jj1].Pnt[jj2])[Y], (*obj.Face[jj1].Pnt[jj2])[Z]);
#endif //WIRKUNGSGLEICH
    } // Flaeche untersucht (ganzes Polygon)
    printf("Symbol: %c\n\n\n\r", obj.Face[jj1].symbol);
  } // alle Objektflaechen untersucht

#ifdef  MIT_LOADCGF
  printCGF (&obj);

  printf ("Pfad und Dateiname des CGF-Objektes\n\r"); 
  printf ("(default: %s): ", CGF_FILE);
  scanf("%s", filnam); 
  if ((filecgf=fopen(filnam, "r"))==NULL && /*File must exist*/
       strcpy(filnam, CGF_FILE) &&
      (filecgf=fopen(filnam, "r"))==NULL) return(-1);
  fclose (filecgf); //war nur zur Probe; loadCGF oeffnet erneut...
  printf ("Dateiname: %s \n\r", filnam);
  loadCGF (&obj, filnam);
  printCGF (&obj);
#endif//MIT_LOADCGF

  printf ("Ende!\n"); _getch(); 

  return (0);
}
